package com.gree.scmservice.controller.saas.admin;

import com.gree.common.entity.ReturnVo;
import com.gree.common.entity.TablePageData;
import com.gree.scmservice.entity.saas.SaasSite;
import com.gree.scmservice.service.saas.SaasSiteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by 180686 on 2021/9/6 15:25
 */
@Api(tags = "站点信息(管理端)")

@RestController
@RequestMapping("/saas/admin/site")
public class AdminSiteController {

    @Autowired
    private SaasSiteService saasSiteService;

    /**
     * 查询站点信息列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询站点信息列表")
    @ApiImplicitParam(name = "saasSite", value = "站点信息", dataType = "SaasSite")
    public ReturnVo<TablePageData<SaasSite>> list(SaasSite saasSite)
    {
        TablePageData<SaasSite> saasSiteTablePageData = saasSiteService.selectSiteList(saasSite);
        return ReturnVo.success(saasSiteTablePageData);
    }

    /**
     * 获取站点信息详细信息
     */
    @GetMapping(value = "/{siteId}")
    @ApiOperation(value = "获取站点信息详细信息")
    @ApiImplicitParam(name = "siteId", value = "站点ID", dataType = "String")
    public ReturnVo getInfo(@PathVariable("siteId") String siteId)
    {
        SaasSite saasSite = saasSiteService.selectSiteById(siteId);
        return ReturnVo.success(saasSite);
    }

    /**
     * 新增站点信息
     */
    @PostMapping
    @ApiOperation(value = "新增站点信息")
    @ApiImplicitParam(name = "saasSite", value = "站点信息", dataType = "SaasSite")
    public ReturnVo add(@RequestBody SaasSite saasSite)
    {
        return saasSiteService.createSite(saasSite);
    }

    /**
     * 修改站点信息
     */
    @PutMapping
    @ApiOperation(value = "修改站点信息")
    @ApiImplicitParam(name = "saasSite", value = "站点信息", dataType = "SaasSite")
    public ReturnVo edit(@RequestBody SaasSite saasSite)
    {
        return ReturnVo.toAjax(saasSiteService.updateSite(saasSite));
    }

    /**
     * 更新站点状态
     */
    @PutMapping(value = "/status")
    @ApiOperation(value = "更新站点状态")
    @ApiImplicitParam(name = "saasSite", value = "站点信息", dataType = "SaasSite")
    public ReturnVo updateStatus(@RequestBody SaasSite saasSite)
    {
        return ReturnVo.toAjax(saasSiteService.updateStatus(saasSite));
    }

    /**
     * 删除站点信息
     */
    @DeleteMapping("/{siteIds}")
    @ApiOperation(value = "删除站点信息")
    @ApiImplicitParam(name = "siteIds", value = "站点ID", dataType = "String[]")
    public ReturnVo remove(@PathVariable String[] siteIds)
    {
        return ReturnVo.toAjax(saasSiteService.deleteSiteByIds(siteIds));
    }

}
